﻿
using PPSMS.Commons;
using PPSMS_Model;

namespace PPSMS.Controllers
{

    public partial class InverterControl : UserControl
    {
        public event Action OnDataReceived;
        public event Action<InverterDevices> OnDetail_Click;
        private InverterDevices _inverter;
        /// <summary>
        /// 逆变器ID
        /// </summary>
        public long InverterID { get; set; }
        /// <summary>
        /// 逆变器型号
        /// </summary>
        public string Model
        {
            get => label2.Text;
            set => label2.Text = value;
        }
        /// <summary>
        /// 制造商
        /// </summary>
        public string Manufacturer
        {
            get => label1.Text;
            set => label1.Text = value;
        }
        /// <summary>
        /// 状态
        /// </summary>
        public string Status
        {
            get => label8.Text;
            set => label8.Text = value;
        }
        /// <summary>
        /// 额定功率
        /// </summary>
        public string Rated_AC_Power
        {
            get => label4.Text;
            set => label4.Text = value;
        }
        /// <summary>
        /// 实时发电功率(动态数据)
        /// </summary>
        public double CurrentPower
        {
            get
            {
                if (!string.IsNullOrWhiteSpace(label5.Text)) return Convert.ToDouble(label5.Text);
                else return 0;
            }
            set => label5.Text = value.ToString();
        }
        /// <summary>
        /// 日发电量(动态数据)
        /// </summary>
        public double DEG
        {
            get => Convert.ToDouble(label6.Text);
            set => label6.Text = value.ToString();
        }
        /// <summary>
        /// 峰值电流
        /// </summary>
        public string Module_Peak_Power
        {
            get => label7.Text;
            set => label7.Text = value;
        }
        public InverterControl()
        {
            InitializeComponent();
        }
        public InverterControl(InverterDevices inverter)
        {
            InitializeComponent();
            _inverter = inverter;
            InverterID = (long)_inverter.InverterID;
            Model = _inverter.Model;
            Manufacturer = _inverter.Manufacturer;
            Rated_AC_Power = _inverter.RatedPower.ToString();
            Module_Peak_Power = _inverter.Module_Peak_Power.ToString();
            Status = "正常";
        }

        private void InverterControl_Load(object sender, EventArgs e)
        {
            InverterID = (long)_inverter.InverterID;
            Model = _inverter.Model;
            Manufacturer = _inverter.Manufacturer;
            Rated_AC_Power = _inverter.RatedPower.ToString();
            Module_Peak_Power = _inverter.Module_Peak_Power.ToString();
            Status = "正常";
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            OnDataReceived?.Invoke();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OnDetail_Click?.Invoke(_inverter);
        }
    }
}
